<?php

class purchase_replenishment
{
	//补货发送ax数据
	public function sendReplenishmentAX($data)
	{
		try {
            $oPo = app::get('purchase')->model('po');
            $safe_data = $oPo->getSafeStock($data, 0, 20000);
            date_default_timezone_set("PRC");
            ini_set('soap.wsdl_cache_enabled', "0"); //关闭wsdl缓存
            ini_set('default_socket_timeout', 100);    // timeout
            $i = 0;
            $branchData=app::get('ome')->model('branch')->dump(array('branch_id'=>$data['branch_id']),'srcorg,branch_id,branch_bn');
            if($branchData['branch_bn']=='ZYC001'){
                $branchData['branch_bn']='W023';
            }
            foreach ($safe_data as $key => $item) {
                $num = $item['max_safe_store'] + $item['store_freeze'] - $item['store'] - $item['arrive_store'];
                if ($num > 0) {
                    $param['list'][$i]['parmHasProcess'] = 1;
                    $param['list'][$i]['parmTransDate'] = time();
                    $param['list'][$i]['parmItemId'] = $item['bn'];
                    $param['list'][$i]['parmInventLocationId'] = $branchData['branch_bn'];
                    $param['list'][$i]['parmUnitId'] = $item['unit'];
                    $param['list'][$i]['parmSafeQty'] = $item['max_safe_store'];
                    $param['list'][$i]['parmRequestSafeQty'] = $num;
                    $i++;
                }
            }
            if ($i > 0) {
                $param['company']=$branchData['srcorg'];
                if(WITH_QIMEN){
                    $res=kernel::single('erpapi_rpc_qimen')->call('SafeInventOMS',$param);
                    $res=json_decode($res,1);
                }else{
                    $webservice_url = HOST_AXToOMs;
                    $client = new SoapClient($webservice_url);
                    $res = $client->__soapCall('SafeInventOMS', array('parameters' => $param));//调用其中test1方法
                    $res['response']['data'] = $res->SafeInventOMSResult;
                }
                
                
                $todate = date('Y-m-d');
                $filename = '/axBH' . $todate . '.log';
                error_log(date('Y-m-d H:i:s') . '数据/' . print_r($param['list'], 1) . '/返回值/' . print_r($res, 1) . PHP_EOL, 3, DATA_DIR . $filename);
                $res_msg = $res['response']['data'];
            }else{
                $res_msg='没有补货数据！';
            }
        } catch (Exception $e) {
            $res_msg=$e->getMessage();
        }
        return $res_msg;
	}
}